package com.dhcc.bpm.modules.metadata.controller;

import io.swagger.annotations.Api;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.modules.metadata.entity.StrucMeta;
import com.dhcc.bpm.modules.metadata.vo.StrucMetaVO;
import com.dhcc.bpm.modules.metadata.service.IStrucMetaService;
import org.springblade.core.boot.ctrl.BladeController;

/**
 *  控制器
 *
 * @author daina
 * @since 2021-04-28
 */
@RestController
@AllArgsConstructor
@RequestMapping("cbus-bpm-boot/strucmeta")
@Api(value = "", tags = "接口")
public class StrucMetaController extends BladeController {

	private IStrucMetaService strucMetaService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入strucMeta")
	public R<StrucMeta> detail(StrucMeta strucMeta) {
		StrucMeta detail = strucMetaService.getOne(Condition.getQueryWrapper(strucMeta));
		return R.data(detail);
	}

	/**
	 * 分页 
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入strucMeta")
	public R<IPage<StrucMeta>> list(StrucMeta strucMeta, Query query) {
		IPage<StrucMeta> pages = strucMetaService.page(Condition.getPage(query), Condition.getQueryWrapper(strucMeta));
		return R.data(pages);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入strucMeta")
	public R<IPage<StrucMetaVO>> page(StrucMetaVO strucMeta, Query query) {
		IPage<StrucMetaVO> pages = strucMetaService.selectStrucMetaPage(Condition.getPage(query), strucMeta);
		return R.data(pages);
	}

	/**
	 * 新增 
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入strucMeta")
	public R save(@Valid @RequestBody StrucMeta strucMeta) {
		return R.status(strucMetaService.save(strucMeta));
	}

	/**
	 * 修改 
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入strucMeta")
	public R update(@Valid @RequestBody StrucMeta strucMeta) {
		return R.status(strucMetaService.updateById(strucMeta));
	}

	/**
	 * 新增或修改 
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入strucMeta")
	public R submit(@Valid @RequestBody StrucMeta strucMeta) {
		return R.status(strucMetaService.saveOrUpdate(strucMeta));
	}

	
	/**
	 * 删除 
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(strucMetaService.removeByIds(Func.toLongList(ids)));
	}

	
}
